﻿Public Class frmDescription

    Public _ContractID As Long
    Public _CaseID As Long
    Public _isContract As Boolean = False
    Public _isDescriptionPlaintiff As Boolean = False
    Public _isDescriptionDefendant As Boolean = False
    Public _isDescriptionThirdParty As Boolean = False

    Private Sub frmDescription_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        reset()
        rtbDescription.SelectionBackColor = Color.White
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Close()
    End Sub

    Private Sub btnClean_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClean.Click
        reset()
    End Sub

    Protected Sub reset()
        rtbDescription.Clear()
        rtbDescription.Focus()
    End Sub

    Protected Function checknull() As Boolean
        Dim oc As New cControl
        If oc.checknull(rtbDescription.Text) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Sub isWhere(ByVal isContract As Boolean, ByVal isDescriptionPlaintiff As Boolean, ByVal isDescriptionDefendant As Boolean, ByVal isDescriptionThirdParty As Boolean)
        _isContract = isContract
        _isDescriptionPlaintiff = isDescriptionPlaintiff
        _isDescriptionDefendant = isDescriptionDefendant
        _isDescriptionThirdParty = isDescriptionThirdParty
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If _isContract Then
            inserted_Description_Contract()
        ElseIf _isDescriptionPlaintiff Then
            inserted_Description_CasePlaintiff()
        ElseIf _isDescriptionDefendant Then
            inserted_Description_CaseDefendant()
        ElseIf _isDescriptionThirdParty Then
            inserted_Description_CaseThirdParty()
        End If
    End Sub

    Protected Sub inserted_Description_Contract()
        Dim oDescription As New cDescription
        If checknull() Then
            If oDescription.insert_Description_Contract(_ContractID, rtbDescription.Rtf, Now, frmMain._User) Then
                MessageBox.Show("រក្សាទុកបានសម្រេច!", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Information)
                reset()
                frmContractEntry.getDescription()
                Close()
            Else
                MessageBox.Show("រក្សាទុកមិនបានសម្រេចទេ", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Else
            MessageBox.Show("សូមបញ្ចូលគ្រប់ពត៌មានទាំងអស់!", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Protected Sub inserted_Description_CasePlaintiff()
        Dim oDescription As New cDescription
        If checknull() Then
            If oDescription.insert_Description_CasePlaintiff(_CaseID, rtbDescription.Rtf, Now, frmMain._User) Then
                MessageBox.Show("រក្សាទុកបានសម្រេច!", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Information)
                reset()
                frmCaseEntry.getDescription_CasePalintiff()
                Close()
            Else
                MessageBox.Show("រក្សាទុកមិនបានសម្រេចទេ", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Else
            MessageBox.Show("សូមបញ្ចូលគ្រប់ពត៌មានទាំងអស់!", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Protected Sub inserted_Description_CaseDefendant()
        Dim oDescription As New cDescription
        If checknull() Then
            If oDescription.insert_Description_CaseDefendant(_CaseID, rtbDescription.Rtf, Now, frmMain._User) Then
                MessageBox.Show("រក្សាទុកបានសម្រេច!", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Information)
                reset()
                frmCaseEntry.getDescription_CaseDefendant()
                Close()
            Else
                MessageBox.Show("រក្សាទុកមិនបានសម្រេចទេ", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Else
            MessageBox.Show("សូមបញ្ចូលគ្រប់ពត៌មានទាំងអស់!", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Protected Sub inserted_Description_CaseThirdParty()
        Dim oDescription As New cDescription
        If checknull() Then
            If oDescription.insert_Description_CaseThirdParty(_CaseID, rtbDescription.Rtf, Now, frmMain._User) Then
                MessageBox.Show("រក្សាទុកបានសម្រេច!", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Information)
                reset()
                frmCaseEntry.getDescription_CaseThirdParty()
                Close()
            Else
                MessageBox.Show("រក្សាទុកមិនបានសម្រេចទេ", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Else
            MessageBox.Show("សូមបញ្ចូលគ្រប់ពត៌មានទាំងអស់!", "រក្សាទុក", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub
End Class